package servlet;

import bean.Announcement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet(urlPatterns ="/getallannouncement")
public class angetallServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        announcementServiceImpl service = new announcementServiceImpl();
        /*service.getAll();
        resp.sendRedirect(req.getContextPath() + "/classset/delete_announcement.jsp");*/
        List<Announcement> list;
        list = service.getAll();

for(int i=0;i< list.size();i++)
{System.out.println(list.get(i).getAnnouncement_num());
    System.out.println(list.get(i).getAnnouncement_title());
    System.out.println(list.get(i).getContent());
}

        req.setAttribute("alist",list);
        req.getRequestDispatcher("getall_announcement.jsp").forward(req,resp);
    }

}